<?php
/**
 * Store and read Password
 *
 * @author     Mario Schillermann <info@rockit-flash.com>
 * @encoding   UTF-8 äöüßÖÄÜ
 * @copyright  © 2011 Mario Schillermann (info@rockit-flash.com)
 * @license    GNU GPL v2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
 * @uses       
 * @package    User
 * @subpackage Model
 * @todo
 */

class User_Model_Password extends Zend_Db_Table_Abstract
{
    
    /**
     * Change password
     * 
     * @param  string $password
     * @param  string $userId
     * @return void
     */
    public function change($password, $userId)
    {
        $data = array('password' => md5($password));
        $where = $this->_db->quoteInto('id = ?', (integer) $userId);
        $this->_db->update('login_users', $data, $where);
    }

    /**
     * Get user data
     *
     * @return string
     */
    public function check($password)
    {
        $query = $this->_db->select()
                           ->from('login_users',
                                  array('COUNT()'))
                           ->where('password = ?', md5($password));

        if ($this->_db->fetchOne($query) > 0) {
            return true;
        }
        return false;
    }
}